package info.erge.search;

public class LineSearch {
    private LineSearch() {
    }

    public static <E> int search(E[] data, E target) {
        for (int i = 0; i < data.length; i++) {
            if (data[i].equals(target)) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        // Integer[] data = {3, 8, 11, 16, 18};
        // System.out.println(LineSearch.search(data, 8));
        // System.out.println(LineSearch.search(data, 1));
        // Student[] students = {
        // new Student("demo"),
        // new Student("erge"),
        // new Student("sample")
        // };
        // System.out.println(LineSearch.search(students, new Student("erge")));
        int[] dataSize = {1000000, 10000000};
        for (int n: dataSize) {
        Integer[] data = ArrayGenerator.generateOrderedArray(n);
        long start = System.nanoTime();
        for (int k = 0; k < 100; k++) {
        LineSearch.search(data, n);
        }
        long end = System.nanoTime();
        System.out.println((end - start) / 1000000000.0);
        }
    }
}
